package com.cssy.xxkj.logic.web;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cssy.base.web.BaseController;
import com.cssy.base.web.BodyMsg;
import com.cssy.xxkj.logic.contants.BillStatusUtil;
import com.cssy.xxkj.logic.entity.LogicMaterialBackDO;
import com.cssy.xxkj.logic.entity.LogicMaterialBackItemDO;
import com.cssy.xxkj.logic.entity.LogicProductionStorageinItemDO;
import com.cssy.xxkj.logic.entity.LogicProductionStorageoutItemDO;
import com.cssy.xxkj.logic.entity.LogicPurchaseWareItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseBatchInItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseMaterialoutItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtherinItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtheroutItemDO;
import com.cssy.xxkj.logic.service.ILogicMaterialBackService;
import com.cssy.xxkj.logic.service.ILogicProductionStorageInService;
import com.cssy.xxkj.logic.service.ILogicProductionStorageOutService;
import com.cssy.xxkj.logic.service.ILogicPurchaseWareService;
import com.cssy.xxkj.logic.service.ILogicWareHouseOtherInService;
import com.cssy.xxkj.logic.service.ILogicWareHouseOtherOutService;
import com.cssy.xxkj.logic.service.ILogicWarehouseBatchInItemService;
import com.cssy.xxkj.logic.service.ILogicWarehouseBatchInService;
import com.cssy.xxkj.logic.service.IMaterialOutService;
import com.cssy.xxkj.logic.util.OftenMothedUtil;
import com.plat.exception.SyBaseException;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.GlobalResLoader;
import com.plat.util.OperationFlag;
import com.plat.util.json.OutJsonGrid;

/**
 * 采购入库退货，其他入库退货、其他出库、领料出库、成品入库、成品出库退货controller
 * @author zeyong.gui
 *
 */
@RequestMapping("/logic/materialback")
@Controller
public class MaterialBackController extends BaseController<LogicMaterialBackDO>  {

	private static final String MANAGER="/xxkj/logic/materialback/MaterialBackManager";
	
	private static final String EDIT="/xxkj/logic/materialback/MaterialBackOperation";// 添加、修改、显示页面
	
	@Resource(name="logicMaterialBackService")
	private ILogicMaterialBackService logicMaterialBackService;
	//采购入库
	@Resource(name="logicPurchaseWareService")
	private ILogicPurchaseWareService logicPurchaseWareService;
	//其他入库
	@Resource(name="logicWareHouseOtherInService")
	private ILogicWareHouseOtherInService logicWareHouseOtherInService;
	//其他入库
	@Resource(name="logicWareHouseOtherOutService")
	private ILogicWareHouseOtherOutService logicWareHouseOtherOutService;
	//领料出库
	@Resource(name="materialOutServiceImpl")
	private IMaterialOutService materialOutServiceImpl;
	//其他入库
	@Resource(name = "logicProductionStorageInService")
	private ILogicProductionStorageInService logicProductionStorageInService;
	//其他入库
	@Resource(name = "logicProductionStorageOutService")
	private ILogicProductionStorageOutService logicProductionStorageOutService;
	
	@Resource(name = "logicWarehouseBatchInService")
	private ILogicWarehouseBatchInService logicWarehouseBatchInService;
	
	@Resource(name = "logicWarehouseBatchInItemService")
	private ILogicWarehouseBatchInItemService logicWarehouseBatchInItemService;
	
	@Resource(name = "oftenMothedUtil")
	private OftenMothedUtil oftenMothedUtil;
	
	@Override
	public String manager(HttpServletRequest request, Model model)
			throws Exception {
		String zdType = request.getParameter("zdType");
		model.addAttribute("zdType", zdType);
		return MANAGER;
	}

	@Override
	public void list(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		scs= this.oftenMothedUtil.getNoFinishConditions(scs, "zd003Statue",BillStatusUtil.MATER_BACK_THREE );
		if(scs.getOrderBy()==null||"".equals(scs.getOrderBy())){
			scs.setOrderBy("bizCreatorDate desc");
		}
		SearchResult result = logicMaterialBackService.findListByExample(scs);
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
		
	}

	@Override
	public String operationForm(HttpServletRequest request, @PathVariable String id,
			@PathVariable String flag, Model model) throws Exception {
		if (OperationFlag.ADD.equals(flag)) {
			model.addAttribute("flag", "ADD");
		} else {
			LogicMaterialBackDO materialBack = logicMaterialBackService.findListById(id);
			model.addAttribute("materBack", materialBack);
		}
		return EDIT;
	}

	@Override
	public Map<String, Object> save(HttpServletRequest request,
			LogicMaterialBackDO curAP, BindingResult result, Model model)
			throws Exception {
		BodyMsg bodyMap = BodyMsg.getInstance();
		try{
			String dataItem = request.getParameter("itemdata");
			if(StringUtils.isBlank(dataItem)){
				bodyMap.isFail();
				bodyMap.configWebInfor("产品列表不能为空！");
				return bodyMap.modelMap;
			}
			logicMaterialBackService.materialBackSave(request, curAP);
			bodyMap.isSuccess();
			bodyMap.configWebInfor(GlobalResLoader.getOpsuccess());
		}catch(Exception e){
			e.printStackTrace();
			bodyMap.isFail();
			bodyMap.configWebInfor(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
		return bodyMap.modelMap;
	}

	@Override
	public Map<String, Object> delete(HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception {
		BodyMsg bodyMap = BodyMsg.getInstance();
		try {
			String ids = request.getParameter("ids");
			String[] fields=ids.split(",");
			for(String field : fields){
				if(StringUtils.isBlank(field)){
					continue;
				}else{
					logicMaterialBackService.deleteBizRemoved(field);
				}
			}
			bodyMap.isSuccess(GlobalResLoader.getOpsuccess());
		} catch (Exception e) {
			e.printStackTrace();
			bodyMap.isFail(GlobalResLoader.getOpfailed() + e.getMessage());
		}
		return bodyMap.modelMap;
	}

	@RequestMapping("/materialItems")
	public void materialItems(HttpServletRequest request, HttpServletResponse response)
		throws Exception{
		String piCode= request.getParameter("piCode");
		if(StringUtils.isEmpty(piCode)){
			piCode=null;
		}else{
			piCode=new String(piCode.getBytes("ISO8859-1"),"UTF-8");
		}
		String zdOriId = request.getParameter("billId");
		String zdType = request.getParameter("billType");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		List<LogicMaterialBackItemDO> gmbmList = new ArrayList<LogicMaterialBackItemDO>();
		if("PCSW".equals(zdType)){
			//采购入库
			paramMap.clear();
			paramMap.put("pcswId", zdOriId);
			List<LogicPurchaseWareItemDO> pcswmList = logicPurchaseWareService.findItemListByMap(paramMap);
			gmbmList = pcswmToCompMaterialBackItem(pcswmList,piCode);
		}else if("GWHN".equals(zdType)){
			//其他入库
			paramMap.clear();
			paramMap.put("gwhInId", zdOriId);
			List<LogicWarehouseOtherinItemDO> gwhnList = logicWareHouseOtherInService.findItemListByMap(paramMap);
			gmbmList = gwhnmToCompMaterialBackItem(gwhnList,piCode);
		}else if("GWHO".equals(zdType)){
			//其他出库
			paramMap.clear();
			paramMap.put("gwhOutId", zdOriId);
			List<LogicWarehouseOtheroutItemDO> gwhoList = logicWareHouseOtherOutService.findItemListByMap(paramMap);
			gmbmList = gwhomToCompMaterialBackItem(gwhoList);
		}else if("GWMO".equals(zdType)){
			//领料出库
			paramMap.clear();
			paramMap.put("gwhmOutId", zdOriId);
			List<LogicWarehouseMaterialoutItemDO> gwmoList = materialOutServiceImpl.findItemListByMap(paramMap);
			gmbmList = gwmomToCompMaterialBackItem(gwmoList);
		}else if("GPSI".equals(zdType)){
			//成品入库
			List<LogicProductionStorageinItemDO> gsgmList = logicProductionStorageInService.findStorInItemList(zdOriId);
			gmbmList = gpsimToCompMaterialBackItem(gsgmList,piCode);
		}else if("GPSO".equals(zdType)){
			//成品出库
			List<LogicProductionStorageoutItemDO> gsgoList = logicProductionStorageOutService.findStorOutItemList(zdOriId);
			gmbmList = gpsomToCompMaterialBackItem(gsgoList);
		}else if("BI".equals(zdType)){
			Map<String, String> parmMap = new HashMap<String, String>();
			parmMap.put("zd001BatchId", zdOriId);
			List<LogicWarehouseBatchInItemDO> itemList=this.logicWarehouseBatchInItemService.findLogicWarehouseBatchInItemByMap(parmMap);
			gmbmList = this.getBatchInItem(itemList);
		}else{
			throw new SyBaseException("没有找到出入库类型。");
		}
		OutJsonGrid out = new OutJsonGrid(gmbmList);
		out.printJSon(response);
	}

	private List<LogicMaterialBackItemDO> getBatchInItem(List<LogicWarehouseBatchInItemDO> itemList) {
		List<LogicMaterialBackItemDO> gmbmList= new ArrayList<LogicMaterialBackItemDO>();
		if(itemList==null||itemList.isEmpty()||itemList.size()==0){
			return gmbmList;
		}else{
			for(LogicWarehouseBatchInItemDO item:itemList){
				if(item==null||StringUtils.isBlank(item.getId())){
					continue;
				}
				LogicMaterialBackItemDO gmbm = new LogicMaterialBackItemDO();
				gmbm.setZd002MaterId(item.getZd002MaterId());
				gmbm.setZd002MaterCode(item.getZd002MaterCode());
				gmbm.setZd002MaterName(item.getZd002MaterName());
				gmbm.setZd002MaterModel(item.getZd002MaterModel());
				gmbm.setZd002MaterSpec(item.getZd002MaterSpec());
				gmbm.setZd002MaterColor(item.getZd002MaterColor());
				gmbm.setZd002MaterQuanlity(item.getZd002MaterQuanlity());
				gmbm.setZd003MaterUnit(item.getZd006Uint());
				gmbm.setZd004MaterPrice(item.getZd007Price());
				gmbm.setZd005OrderQuantity(BigDecimal.ZERO);
				gmbm.setZd006HsSgQuantity(BigDecimal.ZERO);
				BigDecimal whQuantity = item.getZd003InQuantity()==null?BigDecimal.ZERO:item.getZd003InQuantity();
				gmbm.setZd007SgQuantity(whQuantity);
				gmbm.setZd008SumMoney(item.getZd008AllMoney());
				BigDecimal backQuantity = item.getZd003BackInQuantity()==null?BigDecimal.ZERO:item.getZd003BackInQuantity();
				gmbm.setZd009HsBackQuantity(backQuantity);
				gmbm.setZd010TheBackQuantity(whQuantity.subtract(backQuantity));
				gmbm.setZd012PiCode(item.getZd005PiCode());
				gmbmList.add(gmbm);
			}
		}
		return gmbmList;
	}
	//根据采购入库单查询采购入库单的item
	private List<LogicMaterialBackItemDO> pcswmToCompMaterialBackItem(List<LogicPurchaseWareItemDO> pcswmList
			,String piCode){
		List<LogicMaterialBackItemDO> gmbmList = new ArrayList<LogicMaterialBackItemDO>();
		if(pcswmList==null||pcswmList.isEmpty()||pcswmList.size()==0){
			return gmbmList;
		}else{
			for(LogicPurchaseWareItemDO pcswm : pcswmList){
				if(pcswm==null||StringUtils.isBlank(pcswm.getId())){
					continue;
				}
				LogicMaterialBackItemDO gmbm = new LogicMaterialBackItemDO();
				gmbm.setZd002MaterId(pcswm.getZd003MaterId());
				gmbm.setZd002MaterCode(pcswm.getZd004Code());
				gmbm.setZd002MaterName(pcswm.getZd005Name());
				gmbm.setZd002MaterModel(pcswm.getZd007Model());
				gmbm.setZd002MaterSpec(pcswm.getZd011Size());
				gmbm.setZd002MaterColor(pcswm.getZd009Color());
				gmbm.setZd002MaterQuanlity(pcswm.getZd010Quality());
				gmbm.setZd003MaterUnit(pcswm.getZd012Unit());
				gmbm.setZd004MaterPrice(pcswm.getZd016Price());
				gmbm.setZd005OrderQuantity(pcswm.getZd014Quatity());
				gmbm.setZd006HsSgQuantity(pcswm.getZd022InQuantity());
				BigDecimal whQuantity = pcswm.getZd018HsQuantity()==null?BigDecimal.ZERO:pcswm.getZd018HsQuantity();
				gmbm.setZd007SgQuantity(whQuantity);
				gmbm.setZd008SumMoney(pcswm.getZd025SumMoney());
				BigDecimal backQuantity = pcswm.getZd020BackQuantity()==null?BigDecimal.ZERO:pcswm.getZd020BackQuantity();
				gmbm.setZd009HsBackQuantity(backQuantity);
				gmbm.setZd010TheBackQuantity(whQuantity.subtract(backQuantity));
				gmbm.setZd012PiCode(piCode);
				gmbmList.add(gmbm);
			}
			return gmbmList;
		}
	}
	//其他入库
	private List<LogicMaterialBackItemDO> gwhnmToCompMaterialBackItem(List<LogicWarehouseOtherinItemDO> gwhnList
			,String piCode){
		List<LogicMaterialBackItemDO> gmbmList = new ArrayList<LogicMaterialBackItemDO>();
		if(gwhnList==null||gwhnList.isEmpty()||gwhnList.size()==0){
			return gmbmList;
		}else{
			for(LogicWarehouseOtherinItemDO gwhn : gwhnList){
				if(gwhn==null||StringUtils.isBlank(gwhn.getId())){
					continue;
				}
				LogicMaterialBackItemDO gmbm = new LogicMaterialBackItemDO();
				gmbm.setZd002MaterId(gwhn.getZd002MaterialsId());
				gmbm.setZd002MaterCode(gwhn.getZd002MaterialsCode());
				gmbm.setZd002MaterName(gwhn.getZd002MaterialsName());
				gmbm.setZd002MaterModel(gwhn.getZd004MaterialsModel());
				gmbm.setZd002MaterSpec(gwhn.getZd005MaterialsSize());
				gmbm.setZd002MaterColor(gwhn.getZd005MaterialsColor());
				gmbm.setZd002MaterQuanlity(gwhn.getZd005MaterialsQuanlity());
				gmbm.setZd003MaterUnit(gwhn.getZd006Unit());
				gmbm.setZd004MaterPrice(gwhn.getZd009Price());
				gmbm.setZd005OrderQuantity(BigDecimal.ZERO);
				gmbm.setZd006HsSgQuantity(BigDecimal.ZERO);
				BigDecimal whQuantity = gwhn.getZd007Quantity()==null?BigDecimal.ZERO:gwhn.getZd007Quantity();
				gmbm.setZd007SgQuantity(whQuantity);
				gmbm.setZd008SumMoney(gwhn.getZd014SumMoney());
				BigDecimal backQuantity = gwhn.getZd007BackQuantity()==null?BigDecimal.ZERO:gwhn.getZd007BackQuantity();
				gmbm.setZd009HsBackQuantity(backQuantity);
				gmbm.setZd010TheBackQuantity(whQuantity.subtract(backQuantity));
				gmbm.setZd012PiCode(piCode);
				gmbmList.add(gmbm);
			}
			return gmbmList;
		}
	}
	//其他出库
	private List<LogicMaterialBackItemDO> gwhomToCompMaterialBackItem(List<LogicWarehouseOtheroutItemDO> gwhoList){
		List<LogicMaterialBackItemDO> gmbmList = new ArrayList<LogicMaterialBackItemDO>();
		if(gwhoList==null||gwhoList.isEmpty()||gwhoList.size()==0){
			return gmbmList;
		}else{
			for(LogicWarehouseOtheroutItemDO gwho : gwhoList){
				if(gwho==null||StringUtils.isBlank(gwho.getId())){
					continue;
				}
				LogicMaterialBackItemDO gmbm = new LogicMaterialBackItemDO();
				gmbm.setZd002MaterId(gwho.getZd002MaterialsId());
				gmbm.setZd002MaterCode(gwho.getZd002MaterialsCode());
				gmbm.setZd002MaterName(gwho.getZd002MaterialsName());
				gmbm.setZd002MaterModel(gwho.getZd004MaterialsModel());
				gmbm.setZd002MaterSpec(gwho.getZd003MaterialsSpec());
				gmbm.setZd002MaterColor(gwho.getZd016MaterialsColor());
				gmbm.setZd002MaterQuanlity(gwho.getZd017MaterialsQuanlity());
				gmbm.setZd003MaterUnit(gwho.getZd006Unit());
				gmbm.setZd004MaterPrice(gwho.getZd009Price());
				gmbm.setZd005OrderQuantity(BigDecimal.ZERO);
				gmbm.setZd006HsSgQuantity(BigDecimal.ZERO);
				BigDecimal whQuantity = gwho.getZd007Quantity()==null?BigDecimal.ZERO:gwho.getZd007Quantity();
				gmbm.setZd007SgQuantity(whQuantity);
				//出库的总金额先赋值为0
				gmbm.setZd008SumMoney(BigDecimal.ZERO);
				BigDecimal backQuantity = gwho.getZd007BackQuantity()==null?BigDecimal.ZERO:gwho.getZd007BackQuantity();
				gmbm.setZd009HsBackQuantity(backQuantity);
				gmbm.setZd010TheBackQuantity(whQuantity.subtract(backQuantity));
				gmbm.setZd012PiCode(StringUtils.isEmpty(gwho.getZd018PiCode())?null:gwho.getZd018PiCode());
				gmbmList.add(gmbm);
			}
			return gmbmList;
		}
	}
	//领料出库
	private List<LogicMaterialBackItemDO> gwmomToCompMaterialBackItem(List<LogicWarehouseMaterialoutItemDO> gwmoList){
		List<LogicMaterialBackItemDO> gmbmList = new ArrayList<LogicMaterialBackItemDO>();
		if(gwmoList==null||gwmoList.isEmpty()||gwmoList.size()==0){
			return gmbmList;
		}else{
			for(LogicWarehouseMaterialoutItemDO gwmo : gwmoList){
				if(gwmo==null||StringUtils.isBlank(gwmo.getId())){
					continue;
				}
				LogicMaterialBackItemDO gmbm = new LogicMaterialBackItemDO();
				gmbm.setZd002MaterId(gwmo.getZd002MaterialsId());
				gmbm.setZd002MaterCode(gwmo.getZd002MaterialsCode());
				gmbm.setZd002MaterName(gwmo.getZd002MaterialsName());
				gmbm.setZd002MaterModel(gwmo.getZd004MaterialsModel());
				gmbm.setZd002MaterSpec(gwmo.getZd017MaterialsSize());
				gmbm.setZd002MaterColor(gwmo.getZd016MaterialsColor());
				gmbm.setZd002MaterQuanlity(gwmo.getZd018MaterialsQuanlity());
				gmbm.setZd003MaterUnit(gwmo.getZd006Unit());
				gmbm.setZd004MaterPrice(gwmo.getZd009Price());
				gmbm.setZd005OrderQuantity(BigDecimal.ZERO);
				gmbm.setZd006HsSgQuantity(BigDecimal.ZERO);
				BigDecimal whQuantity = gwmo.getZd007Quantity()==null?BigDecimal.ZERO:gwmo.getZd007Quantity();
				gmbm.setZd007SgQuantity(whQuantity);
				//出库的总金额先赋值为0
				gmbm.setZd008SumMoney(BigDecimal.ZERO);
				BigDecimal backQuantity = gwmo.getZd007BackQuantity()==null?BigDecimal.ZERO:gwmo.getZd007BackQuantity();
				gmbm.setZd009HsBackQuantity(backQuantity);
				gmbm.setZd010TheBackQuantity(whQuantity.subtract(backQuantity));
				gmbm.setZd012PiCode(StringUtils.isEmpty(gwmo.getZd021PiCode())?null:gwmo.getZd021PiCode());
				gmbmList.add(gmbm);
			}
			return gmbmList;
		}
	}
	//成品入库
	private List<LogicMaterialBackItemDO> gpsimToCompMaterialBackItem(List<LogicProductionStorageinItemDO> gsgmList
			,String picode){
		List<LogicMaterialBackItemDO> gmbmList = new ArrayList<LogicMaterialBackItemDO>();
		if(gsgmList==null||gsgmList.isEmpty()||gsgmList.size()==0){
			return gmbmList;
		}else{
			for(LogicProductionStorageinItemDO gsgm : gsgmList){
				if(gsgm==null||StringUtils.isBlank(gsgm.getId())){
					continue;
				}
				LogicMaterialBackItemDO gmbm = new LogicMaterialBackItemDO();
				gmbm.setZd002MaterId(gsgm.getZd002MaterialsId());
				gmbm.setZd002MaterCode(gsgm.getZd002MaterialsCode());
				gmbm.setZd002MaterName(gsgm.getZd002MaterialsName());
				gmbm.setZd002MaterModel(gsgm.getZd004MaterialsModel());
				gmbm.setZd002MaterSpec(gsgm.getZd015MaterialsSize());
				gmbm.setZd002MaterColor(gsgm.getZd016MaterialsColor());
				gmbm.setZd002MaterQuanlity(gsgm.getZd017MaterialsQuality());
				gmbm.setZd003MaterUnit(gsgm.getZd006Unit());
				gmbm.setZd004MaterPrice(gsgm.getZd009Price());
				gmbm.setZd005OrderQuantity(BigDecimal.ZERO);
				gmbm.setZd006HsSgQuantity(BigDecimal.ZERO);
				BigDecimal whQuantity = gsgm.getZd007Quantity()==null?BigDecimal.ZERO:gsgm.getZd007Quantity();
				gmbm.setZd007SgQuantity(whQuantity);
				gmbm.setZd008SumMoney(BigDecimal.ZERO);
				BigDecimal backQuantity = gsgm.getZd007BackQuantity()==null?BigDecimal.ZERO:gsgm.getZd007BackQuantity();
				gmbm.setZd009HsBackQuantity(backQuantity);
				gmbm.setZd010TheBackQuantity(whQuantity.subtract(backQuantity));
				gmbm.setZd012PiCode(picode);
				
				gmbmList.add(gmbm);
			}
			return gmbmList;
		}
	}
	//成品出库
	private List<LogicMaterialBackItemDO> gpsomToCompMaterialBackItem(List<LogicProductionStorageoutItemDO> gsgoList){
		List<LogicMaterialBackItemDO> gmbmList = new ArrayList<LogicMaterialBackItemDO>();
		if(gsgoList==null||gsgoList.isEmpty()||gsgoList.size()==0){
			return gmbmList;
		}else{
			for(LogicProductionStorageoutItemDO gsgo : gsgoList){
				if(gsgo==null||StringUtils.isBlank(gsgo.getId())){
					continue;
				}
				LogicMaterialBackItemDO gmbm = new LogicMaterialBackItemDO();
				gmbm.setZd002MaterId(gsgo.getZd002MaterialsId());
				gmbm.setZd002MaterCode(gsgo.getZd002MaterialsCode());
				gmbm.setZd002MaterName(gsgo.getZd002MaterialsName());
				gmbm.setZd002MaterModel(gsgo.getZd004MaterialsModel());
				gmbm.setZd002MaterSpec(gsgo.getZd016MaterialsSize());
				gmbm.setZd002MaterColor(gsgo.getZd017MaterialsColor());
				gmbm.setZd002MaterQuanlity(gsgo.getZd018MaterialsQuality());
				gmbm.setZd003MaterUnit(gsgo.getZd006Unit());
				gmbm.setZd004MaterPrice(gsgo.getZd009Price());
				gmbm.setZd005OrderQuantity(gsgo.getZd021SalesQuanlity());
				gmbm.setZd006HsSgQuantity(BigDecimal.ZERO);
				BigDecimal whQuantity = gsgo.getZd007Quantity()==null?BigDecimal.ZERO:gsgo.getZd007Quantity();
				gmbm.setZd007SgQuantity(gsgo.getZd007Quantity());
				//出库的总金额先赋值为0
				gmbm.setZd008SumMoney(BigDecimal.ZERO);
				BigDecimal backQuantity = gsgo.getZd007BackQuantity()==null?BigDecimal.ZERO:gsgo.getZd007BackQuantity();
				gmbm.setZd009HsBackQuantity(backQuantity);
				gmbm.setZd010TheBackQuantity(whQuantity.subtract(backQuantity));
				gmbm.setZd012PiCode(StringUtils.isEmpty(gsgo.getZd024Picode())?null:gsgo.getZd024Picode());
				gmbmList.add(gmbm);
			}
			return gmbmList;
		}
	}
	
	@RequestMapping("/gridItems")
	public void gridItems(HttpServletRequest request,HttpServletResponse response) throws Exception{
		String backId = request.getParameter("backId");
		if(StringUtils.isNotBlank(backId)){
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("backId", backId);
			List<LogicMaterialBackItemDO> backItemList = logicMaterialBackService.findItemListByMap(paramMap);
			OutJsonGrid out = new OutJsonGrid(backItemList);
			out.printJSon(response);
		}
	}
}
